<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends Vip_Controller
{

    private $uid;

    function __construct()
    {
        parent::__construct();
        $this->load->library('pagination');
        $this->load->library('form_validation');
        $this->uid = $this->session->userdata('user_id');
    }

    public function index($page = 1)
    {
        // 报价列表
        $this->load->model('article_m');
        $page_list = $this->article_m->get_articles_list_by_cate_id(5);
        if (!empty($page_list)) {
            $this->load->model('attachs_m');
            foreach ($page_list as $key => $value) {
                if (!empty($value['article_cover'])) {
                    $access_key                     = $value['article_cover'];
                    $pic                            = $this->attachs_m->get_attachs_by($access_key);
                    $pic_path                       = base_url('uploads/article/' . $access_key . "/" . $pic[0]['file_name']);
                    $page_list[$key]['article_img'] = $pic_path;
                } else {
                    $page_list[$key]['article_img'] = base_url('public/wap/images/logo.png');;
                }
            }
        }
        $data['page_list'] = $page_list;
        // pp($page_list);exit();
        // 最新动态
        // 最新动态
        $this->load->model('file_m');
        $news         = $this->file_m->get_files();
        $data['news'] = $news;
		$this->load->view('user', $data);
	}

    public function page($id)
    {
        $this->load->model('article_m');
        $news         = $this->article_m->get_news_by_id($id);
        $data['news'] = $news;
        $this->load->view('page', $data);
    }

    /**
     * 新闻
     * @param $id
     * @return bool
     */
    public function news($id)
    {
        if (!$id) {
            return false;
        }
        $this->load->model('article_m');
        $news         = $this->article_m->get_news_by_id($id);
        $data['news'] = $news;
        $this->load->view('news', $data);
    }

    /**
     * 新闻列表
     * @param $cate_id
     * @return bool
     */
    public function page_list($cate_id)
    {
        if (!$cate_id) {
            return false;
        }
        $this->load->model('article_m');
        $page_list = $this->article_m->get_articles_list_by_cate_id($cate_id);
        if (!empty($page_list)) {
            $this->load->model('attachs_m');
            foreach ($page_list as $key => $value) {
                if (!empty($value['article_cover'])) {
                    $access_key                     = $value['article_cover'];
                    $pic                            = $this->attachs_m->get_attachs_by($access_key);
                    $pic_path                       = base_url('uploads/article/' . $access_key . "/" . $pic[0]['file_name']);
                    $page_list[$key]['article_img'] = $pic_path;
                } else {
                    $page_list[$key]['article_img'] = base_url('public/wap/images/logo.png');;
                }
            }
        }
        $data['page_list'] = $page_list;
        $this->load->view('page_list', $data);
    }
}